﻿using Games.Common;
using System;
using Xamarin.Forms;

namespace Games.SeriesLights
{
    class GameCell : Label
    {
        private bool isBright;

        private Color Dark = Color.BurlyWood, Bright = Color.Chartreuse;
        public event EventHandler Tapped;

        public GameCell()
        {
            this.BackgroundColor = Dark;
            this.TextColor = Color.SlateGray;
            this.HorizontalTextAlignment = TextAlignment.Center;
            this.VerticalTextAlignment = TextAlignment.Center;
            this.FontAttributes = FontAttributes.Bold;

            TapGestureRecognizer tapGesture = new TapGestureRecognizer { NumberOfTapsRequired = 1 };
            tapGesture.Tapped += (sender, args) =>
            {
                Tapped?.Invoke(this, EventArgs.Empty);
            };
            GestureRecognizers.Add(tapGesture);
        }
        public void InitValue(int value)
        {
            this.Value = value;
            this.IsBright = false;
            this.Text = null;
            //this.Text = this.Value.ToString();
            //this.Opacity = 0.1;
        }

        public void ShowValue()
        {
            this.Text = this.Value.ToString();
            //this.Opacity = 1;
        }

        public int Col { set; get; }

        public int Row { set; get; }
        public int Value { get; private set; }

        public bool IsBright
        {
            set
            {
                if(isBright != value)
                {
                    isBright = value;
                    if(isBright)
                    {
                        this.ColorTo(this.BackgroundColor, Bright, c => this.BackgroundColor = c, 100, Easing.CubicIn);
                    }
                    else
                    {
                        this.ColorTo(this.BackgroundColor, Dark, c => this.BackgroundColor = c, 200, Easing.CubicOut);
                    }
                }
            }
            get
            {
                return isBright;
            }
        }
    }
}
